# -*- encoding: utf-8 -*-
"""
File Name: generate_html_page
Description:
Author : 'lirui'
date: 2024/8/1
Contact: marjey_lee@163.com
Change Activity:
2024/8/1:
"""
from modules.blk.cmdb.cmdb_service import CMDBService

html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>远程会议运维列表</title>
    <style>
        body {
    font-family: Arial, sans-serif;
}

table {
    width: 100%;
    border-collapse: collapse; /* 使边框合并为一个单一的边框 */
    margin: 20px 0;
}

th, td {
    text-align: left; /* 文本左对齐 */
    padding: 8px; /* 单元格内边距 */
    border-bottom: 1px solid #ddd; /* 底部边框 */
}

th {
    background-color: #f2f2f2; /* 表头背景色 */
    color: #333; /* 表头文字颜色 */
}

tr:hover {
    background-color: #f5f5f5; /* 鼠标悬停行背景色 */
}

@media screen and (max-width: 600px) {
    th, td {
        display: block;
        width: 100%;
        text-align: right;
    }

    th:before, td:before {
        content: attr(data-label);
        float: left;
        font-weight: bold;
        text-transform: uppercase;
    }

}
    </style>
</head>
<body>

<table>
    <thead>
    <tr>
        <th>区域</th>
        <th>机构名称</th>
        <th>url</th>
        <th>IP</th>
        <th>协议</th>
        <th>联系人</th>
        <th>联系电话</th>
        <th>备注</th>
    </tr>
    </thead>
    <tbody>
   #{body}
    </tbody>
</table>

</body>
</html>
"""


def _main():
    data = CMDBService().select('remote_meeting_forward')
    d = data['data']['info']
    lines = ''
    for item in d:
        url = f"https://189.8.16.49:{item['nginx_port']}"
        line = f"""    <tr>
         <td>{item['area']}</td>
            <td>{item['branch_name']}</td>
            <td><a href="{url}" target="_blank" > {url} </a></td>
            <td>{item['ip']}</td>
            <td>{item['protocol']}</td>
            <td>{item['contact']}</td>
            <td>{item['telephone_number']}</td>
            <td>{item['notes']}</td>
        </tr>"""
        lines = lines + line
    content = html_content.replace('#{body}', lines)
    print(content.replace('\n', ''))


if __name__ == '__main__':
    _main()
